
var inpText = document.getElementsByClassName('inp-text')[0];
var intBtn = document.getElementsByClassName('inp-btn')[0];
var content = document.querySelector('.content');

intBtn.onclick = function(e){
    var val = inpText.value;
    if(val){
        renderDom('mine' , val);
        inpText.value = "";
        $.ajax({
            url: 'https://developer.duyiedu.com/edu/turing/chat',
            method: 'get',
            data: {
                text:val
            },
            async: true,
            success: function(res){
                console.log(res);
                var data = JSON.parse(res);
                renderDom('robot' , data.text);
            }
        })
    } 
}

function renderDom(who , text){
    var oDiv = document.createElement('div');
    oDiv.className = who;
    oDiv.innerHTML = `<img src="${who == 'mine' ? ('./image/lulu.jpg') : ('./image/qq.jpg')}" alt="" class="image">
    <div class="text">
    ${text}  
    </div>`;
    content.appendChild(oDiv);
    content.scrollTop = content.scrollHeight;
}
